from sqlalchemy.orm import Session
from . import models, schemas

def get_friendship(db: Session, user_id: int, friend_id: int):
    return db.query(models.Friendship).filter(
        (models.Friendship.user_id == user_id) & 
        (models.Friendship.friend_id == friend_id)
    ).first()  # 同步查询，无 await

def create_friendship(db: Session, friendship: schemas.FriendshipCreate):
    db_friendship = models.Friendship(**friendship.dict())
    db.add(db_friendship)
    db.commit()
    db.refresh(db_friendship)
    return db_friendship  # 同步提交，无 await